package com.qww.test02;

import java.util.Random;

class Shape {
    public void draw() {}
    public void erase() {}
}

class Circle extends Shape {
    public void draw() {
        System.out.println("Circle.draw()");
    }
    public void erase() {
        System.out.println("Circle.erase()");
    }
}

class Square extends Shape {
    public void draw() {
        System.out.println("Square.draw()");
    }
    public void erase() {
        System.out.println("Square.erase()");
    }
}

class RandomShapeGenerator {
    private Random rand = new Random(47);
    public Shape next() {
        switch(rand.nextInt(2)) {
            default:
            case 0: return new Circle();
            case 1: return new Square();
        }
    }
}

public class Shapes {
    private static RandomShapeGenerator gen =
            new RandomShapeGenerator();
    public static void main(String[] args) {
        Shape[] s = new Shape[4];
        for(int i = 0; i < s.length; i++) {
            s[i] = gen.next();
        }

        for(Shape shp: s) {
            shp.draw();
        }
    }
}
/* 运行结果
Square.draw()
Circle.draw()
Square.draw()
Circle.draw()
 */